package com.berwin.caper.entry;

import java.util.*;

public class MainThreadTest {


    private static class ThreadTest implements Runnable {

        private List<Long> messageQueen = new ArrayList<>();

        public void pushMessage(Long value) {
            messageQueen.add(value);
        }

        @Override
        public void run() {

            while (true) {
                try {
                    if (messageQueen.size() > 0) {
                        Long value = messageQueen.remove(0);
                        System.out.println("子线程-推出消息:" + value);
                    } else {
                        System.out.println("子线程-没有消息");
                    }
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    public static void main(String[] args) {
//        ThreadTest threadTest = new ThreadTest();
//        new Thread(new Runnable() {
//            @Override
//            public void run() {
//                while (true) {
//                    try {
//                        threadTest.pushMessage(System.currentTimeMillis());
//                        Thread.sleep(500);
//                    } catch (InterruptedException e) {
//                        e.printStackTrace();
//                    }
//                }
//            }
//        }).start();
//        new Thread(threadTest).start();

        Map<Integer, String> map = new HashMap<>();
        List<Integer> list = new ArrayList<>();

        for (int i = 0; i < 100000; i++) {
            map.put(i, i + "");
            list.add(i);
        }
        Collections.shuffle(list);
        long start = System.currentTimeMillis();
        System.out.println("map:" + map.get(50000));
        System.out.println((System.currentTimeMillis() - start));
        start = System.currentTimeMillis();
        for (int i = 0; i < list.size(); i++) {
            if (i == 50000) {
                System.out.println("list:" + i);
                System.out.println((System.currentTimeMillis() - start));
                return;
            }
        }
    }
}
